let input = `4
3310120150912233 2 4
3310120150912119 4 1
3310120150912126 1 3
3310120150912002 3 2
2
3 4`
let input_arr = input.split('\n')



let count = parseInt(input_arr[0])
let student_exam_infos = []
for(let i = 0; i < count; i++){
    let arr =input_arr[i+1].split(' ')
    let student_exam_object = {
        student_exam_no:arr[0],
        try_seat_no:arr[1],
        exam_seat_no: arr[2]
    }
student_exam_infos.push(student_exam_object)
}

let query_no = input_arr[input_arr.length-1]
let query_arr = query_no.split(' ')

for(let search_no of query_arr){
    let tmp_arr = student_exam_infos.filter((item)=>item.try_seat_no === search_no)
console.log(`${tmp_arr[0].student_exam_no} ${tmp_arr[0].exam_seat_no}`);
}